package com.zlx.xbhy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zlx.xbhy.entity.Article;
import com.zlx.xbhy.entity.User;
import com.zlx.xbhy.mapper.ArticleMapper;
import com.zlx.xbhy.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author 周罗校
 * @Description
 * @ClassName ArticleServiceImpl
 * @date 2020.11.18 15:13:37
 * 该版权归周罗校所有，最终解释权以官方为准
 */
@Service
@Transactional
public class ArticleServiceImpl extends BaseServiceImpl<Article,Long> implements ArticleService {
    @Autowired
    private ArticleMapper mapper;


    /**
     * @Author 周罗校
     * @Description 文章分页
     * @Param [title, start, pageSize]
     * @return com.github.pagehelper.PageInfo<com.zlx.xbhy.entity.Article>
     * @Date 2020.11.18 15:17:50
     **/
    @Override
    public PageInfo<Article> selectPage(String title, Integer start, Integer pageSize) {
        PageHelper.startPage(start,pageSize);
        return new PageInfo<>(mapper.selectPage(title));
    }
    /*
     * @Author Edward
     * @Description 查询收藏的文章
     * @Date 19:32 2020/11/19
     * @Param [title, uId, start, pageSize]
     * @return com.github.pagehelper.PageInfo<com.zlx.xbhy.entity.Article>
     **/
    @Override
    public PageInfo<Article> selectFavoritePage(String title, Long uId, Integer start, Integer pageSize) {
        PageHelper.startPage(start,pageSize);
        return new PageInfo<>(mapper.selectFavoritePage(uId,title));
    }

    @Override
    public List<Article> countNew() {
        List<Article> list = new ArrayList<>();
        Collections.addAll(list, mapper.countNew(0), mapper.countNew(1),
                mapper.countNew(2), mapper.countNew(3), mapper.countNew(4),
                mapper.countNew(5), mapper.countNew(6),mapper.countNew(7),mapper.countNew(8));
        Collections.reverse(list);
        return list;
    }
}
